#!/usr/bin/env python
# -*- coding: utf-8 -*-

"ReST Class mapping to SQL table"

#from django.db import models
import django.db.models.options as options
from django.utils.html import format_html
from labman2.data.models import Base, rest_to_html
from labman2.data.subdata.Fact.models import Fact

options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('help_texts',)

#==============================================================================
class ReST(Fact):
    "A reStructuredText, a simple markup format; no own data, just formatting"

    class Meta(): # pylint: disable=C0111,C1001,W0232,R0903
        help_texts = {
          'name': 'You can use ReST formating here.',
          'description': '''
A reasonable introduction to reST syntax:
<a href="http://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html">
http://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html</a>''',
          }

    def __unicode__(self):

        try:
            return format_html(u'{0}: {1} :{2}',
                           rest_to_html(self.name),
                           rest_to_html(self.description),
                           Base.__unicode__(self))
        except StandardError as err:
            print "ReST.__unicode__", err
            return u'%s: %s :%s' % (
                           self.name,
                           self.description,
                           Base.__unicode__(self))

    def show_details(self):

        name = rest_to_html(self.name)
        description = rest_to_html(self.description)
        info_dict = [('Name', name),
                     ('Description', description)]
        info_dict.extend(Base.show_details(self))
        return info_dict
